1
|
|
|
define(['snabbdom', 'helper', 'moment'], function (V, helper, moment) { |
2
|
|
|
'use strict'; |
3
|
|
|
V = V.default; |
4
|
|
|
|
5
|
|
|
var self = {}; |
6
|
|
|
|
7
|
|
|
function showBar(v, width, warning) { |
8
|
|
|
return V.h('span', |
9
|
|
|
{ props: { className: 'bar' + (warning ? ' warning' : '') } }, |
10
|
|
|
[ |
11
|
|
|
V.h('span', |
12
|
|
|
{ |
13
|
|
|
style: { width: (width * 100) + '%' } |
14
|
|
|
}), |
15
|
|
|
V.h('label', v) |
16
|
|
|
] |
17
|
|
|
); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
self.showStatus = function showStatus(d) { |
21
|
|
|
return V.h('td', |
22
|
|
|
{ props: { className: d.is_online ? 'online' : 'offline' } }, |
23
|
|
|
_.t((d.is_online ? 'node.lastOnline' : 'node.lastOffline'), { |
24
|
|
|
time: d.lastseen.fromNow(), |
25
|
|
|
date: d.lastseen.format('DD.MM.YYYY, H:mm:ss') |
26
|
|
|
})); |
27
|
|
|
}; |
28
|
|
|
|
29
|
|
|
self.showGeoURI = function showGeoURI(d) { |
30
|
|
|
if (!helper.hasLocation(d)) { |
31
|
|
|
return undefined; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return V.h('td', |
35
|
|
|
V.h('a', |
36
|
|
|
{ props: { href: 'geo:' + d.location.latitude + ',' + d.location.longitude } }, |
37
|
|
|
Number(d.location.latitude.toFixed(6)) + ', ' + Number(d.location.longitude.toFixed(6)) |
38
|
|
|
) |
39
|
|
|
); |
40
|
|
|
}; |
41
|
|
|
|
42
|
|
|
self.showGateway = function showGateway(d) { |
43
|
|
|
return d.is_gateway ? _.t('yes') : undefined; |
44
|
|
|
}; |
45
|
|
|
|
46
|
|
|
self.showFirmware = function showFirmware(d) { |
47
|
|
|
return [ |
48
|
|
|
helper.dictGet(d, ['firmware', 'release']), |
49
|
|
|
helper.dictGet(d, ['firmware', 'base']) |
50
|
|
|
].filter(function (n) { |
51
|
|
|
return n !== null; |
52
|
|
|
}).join(' / ') || undefined; |
53
|
|
|
}; |
54
|
|
|
|
55
|
|
|
self.showUptime = function showUptime(d) { |
56
|
|
|
return moment.utc(d.uptime).local().fromNow(true); |
57
|
|
|
}; |
58
|
|
|
|
59
|
|
|
self.showFirstSeen = function showFirstSeen(d) { |
60
|
|
|
return d.firstseen.fromNow(true); |
61
|
|
|
}; |
62
|
|
|
|
63
|
|
|
self.showLoad = function showLoad(d) { |
64
|
|
|
return showBar(d.loadavg.toFixed(2), d.loadavg / (d.nproc || 1), d.loadavg >= d.nproc); |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
self.showRAM = function showRAM(d) { |
68
|
|
|
return showBar(Math.round(d.memory_usage * 100) + ' %', d.memory_usage, d.memory_usage >= 0.8); |
69
|
|
|
}; |
70
|
|
|
|
71
|
|
|
self.showSite = function showSite(d) { |
72
|
|
|
var rt = d.site_code; |
73
|
|
|
if (config.siteNames) { |
74
|
|
|
config.siteNames.forEach(function (t) { |
75
|
|
|
if (d.site_code === t.site) { |
76
|
|
|
rt = t.name; |
77
|
|
|
} |
78
|
|
|
}); |
79
|
|
|
} |
80
|
|
|
return rt; |
81
|
|
|
}; |
82
|
|
|
|
83
|
|
|
self.showClients = function showClients(d) { |
84
|
|
|
if (!d.is_online) { |
85
|
|
|
return undefined; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
var clients = [ |
89
|
|
|
V.h('span', [ |
90
|
|
|
d.clients > 0 ? d.clients : _.t('none'), |
91
|
|
|
V.h('br'), |
92
|
|
|
V.h('i', { props: { className: 'ion-people', title: _.t('node.clients') } }) |
93
|
|
|
]), |
94
|
|
|
V.h('span', |
95
|
|
|
{ props: { className: 'legend-24ghz' } }, |
96
|
|
|
[ |
97
|
|
|
d.clients_wifi24, |
98
|
|
|
V.h('br'), |
99
|
|
|
V.h('span', { props: { className: 'symbol', title: '2,4 Ghz' } }) |
100
|
|
|
]), |
101
|
|
|
V.h('span', |
102
|
|
|
{ props: { className: 'legend-5ghz' } }, |
103
|
|
|
[ |
104
|
|
|
d.clients_wifi5, |
105
|
|
|
V.h('br'), |
106
|
|
|
V.h('span', { props: { className: 'symbol', title: '5 Ghz' } }) |
107
|
|
|
]), |
108
|
|
|
V.h('span', |
109
|
|
|
{ props: { className: 'legend-others' } }, |
110
|
|
|
[ |
111
|
|
|
d.clients_other, |
112
|
|
|
V.h('br'), |
113
|
|
|
V.h('span', { props: { className: 'symbol', title: _.t('others') } }) |
114
|
|
|
]) |
115
|
|
|
]; |
116
|
|
|
|
117
|
|
|
return V.h('td', { props: { className: 'clients' } }, clients); |
118
|
|
|
}; |
119
|
|
|
|
120
|
|
|
self.showIPs = function showIPs(d) { |
121
|
|
|
var string = []; |
122
|
|
|
var ips = d.addresses; |
123
|
|
|
ips.sort(); |
124
|
|
|
ips.forEach(function (ip, i) { |
125
|
|
|
if (i > 0) { |
126
|
|
|
string.push(V.h('br')); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if (ip.indexOf('fe80:') !== 0) { |
130
|
|
|
string.push(V.h('a', { props: { href: 'http://[' + ip + ']/', target: '_blank' } }, ip)); |
131
|
|
|
} else { |
132
|
|
|
string.push(ip); |
133
|
|
|
} |
134
|
|
|
}); |
135
|
|
|
return V.h('td', string); |
136
|
|
|
}; |
137
|
|
|
|
138
|
|
|
self.showAutoupdate = function showAutoupdate(d) { |
139
|
|
|
return d.autoupdater.enabled ? _.t('node.activated', { branch: d.autoupdater.branch }) : _.t('node.deactivated'); |
140
|
|
|
}; |
141
|
|
|
|
142
|
|
|
return self; |
143
|
|
|
}); |
144
|
|
|
|